# -*-  coding:utf-8 -*-
# Author : lihongliang
print("第一题".center(50,"*"))
names =[]
names.append('old_driver')
names.append('rain')
names.append('jack')
names.append('shanshan')
names.append('peiqi')
names.append('black_girl')
print(names)
print("第二题".center(50,"*"))
print(names.index("black_girl"))
names.insert(5,"alex")
print(names)
print("第三题".center(50,"*"))
print(names.index("shanshan"))
names[3]="姗姗"
print(names)
print("第四题".center(50,"*"))
names.insert(7,["oldboy","oldgirl"])
print(names)
print("第五题".center(50,"*"))
peiqi = names.index("peiqi")
print(peiqi)
print("第六题".center(50,"*"))
number = [1,2,3,4,5,6,7,2,4,6,2]
names.extend(number)
print(names)
print(" 第七题 ".center(50,"*"))
a4= names[4:8]
print(a4)
print(" 第八题 ".center(50,"*"))
a5 = names[2:11:2]
print(a5)
print(" 第九题 ".center(50,"*"))
print(names[-3:])

print(" 第十题 ".center(50,"*"))

for i in names:
    print(names.index(i)+1, i)

print("方法二")
count = 0
for i in names:
    print(count,i)
    count += 1
print("方法三")
for  index, i  in enumerate(names):
    print(index,i)

# 11 循环names列表，打印每个元素的索引值和元素，当索引值未偶数时，吧对应元素改为-1
print(names)
print("===========题目11============")
for i in names:
    print(names.index(i), i)
    if names.index(i) % 2  == 0:
        names[names.index(i)]=-1
print(names)

#12 names有3个2，返回第2个2，要动态找
print("========题目12=============")
first_index = names.index(2)
new_list = names[first_index+1:]
second_index = new_list.index(2)
second_val = names[first_index + second_index +1]
print(new_list,first_index,second_index)
print("second vales:",second_val)



# 13
print("========题目13=============")
products = [['iphone8',6888],['MacPro',14800],['小米6',2499],['coffee',31],['Book',80],['Nike Shoes',799]]

print("==========商品列表：============")
for i in products:
    print(products.index(i),i[0],i[1])
shopping_car = []
print("方式二：")
for index,p in enumerate(products):
    print("%s ,%s,%s"% (index,p[0],p[1]))


# 14
print("===========题目14==============")
flag = True
while flag:
    print("==========商品列表：============")
    for i in products:
        print(products.index(i), i[0], i[1])
        #print(products.index(i))

    select =input("请输入需要购买的商品代码（退出请按Q/q）：")
    # shopping_car.append(products[select])
    # print(products[select])

    if select.isdigit():
        select = int(select)
        if select >=0 and select <=len(products):
            shopping_car.append(products[select])
            print("Added product %s into shopping cart." % products[select])
        else:
            print("商品不存在！")
    elif select == "Q" or "q":
        if len(shopping_car)>0:
            print("你已经购买以下商品")
            for index,p in  enumerate(shopping_car):
                print("%s ,%s,%s" % (index, p[0], p[1]))
        break
        flag = False





